package com.tmtc.controller.driver;

import com.tmtc.constant.ParameterConstant;
import com.tmtc.controller.appAPI.BaseController;
import com.tmtc.service.appAPI.ValidTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/App/valid")
public class ValidTimeController extends BaseController {

	@Autowired
	ValidTimeService validTimeService;

	/**
	 * 验证卡的有效时间 url:/App/valid/time
	 * 
	 * @param request
	 * @param company_id
	 * @param card_num
	 * @param user_type
	 * @param line_id
	 * @param line_time_id
	 * @param line_station_id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/time")
	public Map<String, Object> time(HttpServletRequest request, @RequestParam String company_id,
			@RequestParam String card_num, @RequestParam Integer user_type, @RequestParam String line_id,
			@RequestParam String line_time_id, @RequestParam String line_station_id) {

		if ("0".equals(card_num)) {
			return getMap(request, "无效卡", STATUS_ERROR);
		}
		
		if (ParameterConstant.USER_TYPE_COMPANY != user_type) {
			return getMap(request, "您不是免费员工", STATUS_ERROR);
		}

		int time = validTimeService.insertTime(company_id, card_num, user_type, line_id, line_time_id, line_station_id);
		switch (time) {
		case 1:
			return getMap(request, "无效卡", STATUS_ERROR);
		case 2:
			return getMap(request, "您不是免费员工", 2);
		case 3:
			return getMap(request, "请激活卡", 3);
		case 5:
			return getMap(request, "已刷卡，请上车", 4);
		default:
			break;
		}
		return getMap(request, "请上车");
	}
}
